package com.smile.weather.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smile.weather.R;
import com.smile.weather.bean.DayWeatherData;
import com.smile.weather.bean.HourWeatherData;

import java.util.List;

/**
 * Created by smile on 2016/8/23.
 */
public class RecyclerAdapter_Day extends RecyclerView.Adapter<RecyclerAdapter_Day.ViewHolder> {
    private List<DayWeatherData> mDatas;
    private Context mContext;

    public RecyclerAdapter_Day(Context context, List<DayWeatherData> mDatas) {
        this.mDatas = mDatas;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_day, null);
        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        DayWeatherData data = mDatas.get(position);
        holder.tv_date.setText(data.getDate());
        holder.tv_date2.setText(data.getDate2());
        if (data.getWeather_icon1().equals("")) {
            data.setWeather_icon1("no");
        }
        if (data.getWeather_icon2().equals("")) {
            data.setWeather_icon2("no");
        }
        holder.iv_weather_icon1.setImageResource(mContext.getResources().getIdentifier(data.getWeather_icon1(),
                "drawable",
                "com.smile.weather"));
        holder.iv_weather_icon2.setImageResource(mContext.getResources().getIdentifier(data.getWeather_icon2(),
                "drawable",
                "com.smile.weather"));
        holder.tv_weather.setText(data.getWeather());
        holder.tv_temperature.setText(data.getTemperature());
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_date;
        public TextView tv_date2;
        public ImageView iv_weather_icon1;
        public ImageView iv_weather_icon2;
        public TextView tv_weather;
        public TextView tv_temperature;

        /**
         * @param itemView
         * @Description: TODO
         */
        public ViewHolder(View itemView) {
            super(itemView);
            tv_date = (TextView) itemView.findViewById(R.id.tv_date);
            tv_date2 = (TextView) itemView.findViewById(R.id.tv_date2);
            iv_weather_icon1 = (ImageView) itemView.findViewById(R.id.iv_weather_icon1);
            iv_weather_icon2 = (ImageView) itemView.findViewById(R.id.iv_weather_icon2);
            tv_weather = (TextView) itemView.findViewById(R.id.tv_weather);
            tv_temperature = (TextView) itemView.findViewById(R.id.tv_temperature);
        }
    }

}
